//
//  ResetPasswordsVM.swift
//  LeTu
//
//  Created by g1 on 2024/1/4.
//

import Foundation

class ResetPasswordsVM {
    
    // MARK: - 重置密码
    func resetPasswords(params: [String: Any], completeHandle: @escaping NetworkRequestHandle) {
        
        apiProvider.request(api: .resetPassword(params: params)) { json, jsonArr, code in
            
            MYLog("重置密码：",json)
            
            var dialog = DialogMessage()
            
            guard code == 200, let pm = Mapper<ResponseModel>().map(JSON: json) else { return completeHandle(dialog) }
            dialog.code = pm.code
            dialog.message = pm.msg
            // 解析data数据
            guard let data = pm.data as? [String : Any], let responseModel = Mapper<LoginResp>().map(JSON: data), pm.code == 200 && responseModel.token.count > 0  else { return completeHandle(dialog) }
            completeHandle(dialog)
            
        } failureHandler: { error in
            completeHandle(DialogMessage())
        }
        
    }
    
}

